//
//  HomeViewController.m
//  MazeG
//
//  Created by cdh on 11/2/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "HomeViewController.h"
#import "BoardViewController.h"

@implementation HomeViewController

@synthesize startButton;
@synthesize boardViewController;

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	
	self.wantsFullScreenLayout = YES;
	[self setupHomeView];
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
	[backgroundImage release];
	[titleLabel release];
	[startButton release];
}

- (void) setupHomeView {
	self.view.backgroundColor = [UIColor blackColor];
	self.view.frame = [UIScreen mainScreen].applicationFrame;
	
	// set up background image
	//backgroundImage = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"homeImage.png"]];
	//backgroundImage.center = self.view.center;
	//backgroundImage.opaque = YES;
	
	// set up title label
	titleLabel = [[UILabel alloc] initWithFrame: CGRectMake(self.view.center.x - 75.0, self.view.center.y - 150.0, 150.0, 50.0)];
	titleLabel.font = [UIFont boldSystemFontOfSize: 20.0];
	titleLabel.backgroundColor = [UIColor blackColor];
	titleLabel.textColor = [UIColor blueColor];
	titleLabel.textAlignment = UITextAlignmentCenter;
	titleLabel.text = [NSString stringWithFormat:@"Maze Game"];
	
	// set up start button
	startButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
	startButton.titleLabel.font = [UIFont boldSystemFontOfSize: 20.0];
	startButton.titleLabel.textColor = [UIColor redColor];
	startButton.titleLabel.textAlignment = UITextAlignmentCenter;
	startButton.frame = CGRectMake(self.view.center.x - 40.0, self.view.center.y, 80.0, 30.0);
	[startButton setTitleColor: [UIColor blueColor] forState: UIControlStateNormal];
	[startButton setTitle: @"START" forState: UIControlStateNormal];
	[startButton addTarget: self action:@selector(startGame) forControlEvents:UIControlEventTouchUpInside];
	
	//[self.view addSubview: backgroundImage];
	[self.view addSubview: titleLabel];
	[self.view addSubview: startButton];
	
}

- (void) startGame {
	BoardViewController * aViewController = [[BoardViewController alloc] init];
	self.boardViewController = aViewController;
	[aViewController release];
	boardViewController.view.frame = [UIScreen mainScreen].applicationFrame;
	[self.view addSubview: [boardViewController view]];
	//[self.view bringSubviewToFront: [boardViewController view]];
}

@end
